package com.sjp.utils;

import com.sjp.entity.Brand;

import java.util.Random;

public class BrandUtils {
    private static Random random = new Random();
    public static String[] brandNames =
            {"刷子", "剪刀", "叉子", "手套", "水桶", "火", "玉米",
                    "球", "瓶子", "白菜", "稻草", "肉腿", "胡萝卜",
                    "苹果", "铃铛", "青草"};

    public static String getBrandName() {
        int index = random.nextInt(brandNames.length);
        return brandNames[index];
    }

    public static Brand[] bulderBrand(int capacity) {
        Brand[] brands = new Brand[capacity];
        for (int i = 0; i < brands.length; i += 3) {
            String brandName = getBrandName();

            Brand brand1 = new Brand(brandName);
            Brand brand2 = new Brand(brandName);
            Brand brand3 = new Brand(brandName);

            brands[i] = brand1;
            brands[i + 1] = brand2;
            brands[i + 2] = brand3;
        }
        System.out.println("============随机打乱数组元素===========");
        for (int i = 0; i < brands.length; i++) {

            Brand brandA = brands[i];

            int randomIndex = random.nextInt(brands.length);

            Brand brandB = brands[randomIndex];

            Brand temp = brandA;
            brands[i] = brandB;
            brands[randomIndex] = temp;
        }
        return brands;
    }
}
